package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.CityInfo;
import com.atguigu.lease.model.entity.DistrictInfo;
import com.atguigu.lease.model.entity.ProvinceInfo;
import com.atguigu.lease.web.admin.service.CityInfoService;
import com.atguigu.lease.web.admin.service.DistrictInfoService;
import com.atguigu.lease.web.admin.service.ProvinceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 22:40$
 * description: 地区信息管理、
 */
@Tag(name = "地区信息管理")
@RestController
@RequestMapping("/admin/region/")
public class RegionInfoController {
//    省份
    @Autowired
    private ProvinceInfoService provinceInfoService;
//     区县
    @Autowired
    private DistrictInfoService districtInfoService;
//    城市
    @Autowired
    private CityInfoService cityInfoService;
    /**
     * 查询省份信息列表
     */

    @GetMapping("/province/list")
    @Operation(summary = "查询省份信息列表")
    public Result<List<ProvinceInfo>> getProvinceList() {
        List<ProvinceInfo> list = provinceInfoService.list();
        return Result.ok(list);
    }
    /**
     * 根据城市id查询区县信息
     * */
    @GetMapping("district/listByCityId")
    @Operation(summary = "根据城市id查询区县信息")
    public Result<List<DistrictInfo>> getDistrictListByCityId(
            @RequestParam Long id) {
        LambdaQueryWrapper<DistrictInfo> districtInfoLambdaQuery = new LambdaQueryWrapper<>();
        districtInfoLambdaQuery.eq(DistrictInfo::getCityId, id);
        List<DistrictInfo> list = districtInfoService.list(districtInfoLambdaQuery);
        return Result.ok(list);
    }
    /**
     * 根据省份id查询城市信息列表
     * */
    @GetMapping("/city/listByProvinceId")
    @Operation(summary = "根据省份id查询城市信息列表")
    public Result<List<CityInfo>> getCityListByProvinceId(@RequestParam Long id) {
        LambdaQueryWrapper<CityInfo> cityInfoLambdaQuery = new LambdaQueryWrapper<>();
        cityInfoLambdaQuery.eq(CityInfo::getProvinceId,id);
        List<CityInfo> list = cityInfoService.list(cityInfoLambdaQuery);
        return Result.ok(list);
    }

}
